package onlinejudge.util;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.springframework.web.multipart.MultipartFile;

public class FileUtil {
	
	/**
	 * 文件上传
	 * @param file
	 * @return
	 */
	public String fileUpload(MultipartFile file,String path) {
		try {
			File currentFile = new File(path);
			file.transferTo(currentFile);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return file.getOriginalFilename();
	}
	
	/**
	 * 写入文件
	 * @param content
	 * @param filePath
	 */
	public static void writeFile(String content,String filePath) {
        try {
       	 BufferedWriter out = new BufferedWriter(new FileWriter(filePath));
       	 out.write(content);
       	 out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}    
	}
}
